// D3D9RenderUnit.cpp

#include "stdafx.h"

#include "D3D9IndexBuffer.h"
#include "D3D9VertexBuffer.h"

#include "D3D9RenderUnit.h"

//////////////////////////////////////////////////////////////////////////
CD3D9RenderUnit::CD3D9RenderUnit(void) : 
m_pVB(NULL), m_pIB(NULL), m_arrayMaterial(NULL), m_pDecl(NULL),
m_nBaseVertexIndex(0), m_nMinIndex(0), m_nNumVertices(0),
m_nStartIndex(0), m_nPrimitiveCount(0)
{

}

CD3D9RenderUnit::~CD3D9RenderUnit()
{

}

//////////////////////////////////////////////////////////////////////////
IDirect3DVertexBuffer9* CD3D9RenderUnit::GetVB() const
{
	return m_pVB->GetBuffer();
}

IDirect3DIndexBuffer9* CD3D9RenderUnit::GetIB() const
{
	return m_pIB->GetBuffer();
}

IDirect3DTexture9* CD3D9RenderUnit::GetTex() const
{
	return m_arrayMaterial->m_pTex;
}

D3DMATERIAL9* CD3D9RenderUnit::GetMtrl() const
{
	return m_arrayMaterial->m_pMtrl;
}

IDirect3DVertexDeclaration9* CD3D9RenderUnit::GetDecl() const
{
	return m_pDecl;
}

int CD3D9RenderUnit::GetMinIndex(void) const
{
	return m_nMinIndex;
}

int CD3D9RenderUnit::GetNumVertices(void) const
{
	return m_nNumVertices;
}

int CD3D9RenderUnit::GetPrimitiveCount(void) const
{
	return m_nPrimitiveCount;
}

int CD3D9RenderUnit::GetStartIndex(void) const
{
	return m_nStartIndex;
}

int CD3D9RenderUnit::GetBaseVertexIndex(void) const
{
	return m_nBaseVertexIndex;
}

int CD3D9RenderUnit::GetVertexSize(void) const
{
	return m_nSizeofVertex;
}

//////////////////////////////////////////////////////////////////////////
void CD3D9RenderUnit::SetVB(CD3D9VertexBuffer* pVB)
{
	m_pVB = pVB;
}

void CD3D9RenderUnit::SetIB(CD3D9IndexBuffer* pIB)
{
	m_pIB = pIB;
}

void CD3D9RenderUnit::SetDecl(LPDIRECT3DVERTEXDECLARATION9 pDecl)
{
	m_pDecl = pDecl;
}

void CD3D9RenderUnit::SetBaseVertexIndex(int nBaseVertexIndex)
{
	m_nBaseVertexIndex = nBaseVertexIndex;
}

void CD3D9RenderUnit::SetMinIndex(int nMinIndex)
{
	m_nMinIndex = nMinIndex;
}

void CD3D9RenderUnit::SetNumVertices(int nNumVertices)
{
	m_nNumVertices = nNumVertices;
}

void CD3D9RenderUnit::SetPrimitiveCount(int nNumTri)
{
	m_nPrimitiveCount = nNumTri;
}

void CD3D9RenderUnit::SetStartIndex(int nStartIndex)
{
	m_nStartIndex = nStartIndex;
}

void CD3D9RenderUnit::SetVertexSize(int nSizeVertex)
{
	m_nSizeofVertex = nSizeVertex;
}

void CD3D9RenderUnit::UpdateVB(size_t offset, size_t length, const void *pSource)
{
	if (!m_pVB)
	{
		return;
	}

	m_pVB->write(offset, length, pSource, true);
}

void CD3D9RenderUnit::UpdateIB(size_t offset, size_t length, const void *pSource)
{
	if (!m_pIB)
	{
		return;
	}

	m_pIB->write(offset, length, pSource, true);
}